// 引入刚刚在第五点建立连接mysql数据库的db.js文件
const { DataTypes } = require('sequelize');
const db = require('../config/db');
// 引入Sequelize对象
const { sequelize } = db;
// 引入上一步的文章数据表模型文件
const txhRecall = require('../schema/txhRecall')(sequelize, DataTypes);

// 自动创建表
txhRecall.sync({ force: false });

class txhRecallModel {
  static async createData(data) {
    return await txhRecall.create({
      content: data.content, // 内容
    });
  }

  static async deleteContent(id) {
    return await txhRecall.destroy({
      where: {
        id,
      },
    });
  }

  static async findContentById(id) {
    return await txhRecall.findAll({
      where: {
        id,
      },
    });
  }

  static async findContentByContent(content) {
    return await txhRecall.findAll({
      where: {
        content,
      },
    });
  }

  static async updateContentById(id, content) {
    return await txhRecall.update({
      content,
    }, {
      where: {
        id,
      },
    });
  }
}

module.exports = txhRecallModel;
